package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.jsola.core.query.BaseQuery;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;


/**
 * 员工考勤表
 *
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class EmpAttendanceQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = "姓名/手机号")
    private String nameOrPhone;

    @ApiParam(value = "用工单位id", required = true)
    private String companyId;

    @ApiParam(value = "用工单位id", required = true)
    @NotNull(message = "用工单位id不能为空")
    private String[] companyIdList;

    @ApiParam(value = "渠道id")
    private String channelId;

    @ApiParam(value = "年份", required = true)
    @NotNull(message = "年份不能为空")
    private Integer yearly;

    @ApiParam(value = "月份", required = true)
    @NotNull(message = "月份不能为空")
    private Integer monthly;

    @ApiParam(value = "天", required = true)
    @NotNull(message = "天不能为空")
    private Integer daily;

    @ApiParam(value = "员工id")
    private String empId;


    @ApiParam(value = "排序字段", allowMultiple = true, type = "Order", example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public EmpAttendanceQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

}

